Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 Search this book:
Previous | Table of Contents | Next
#### The Invoices Form The Invoices form will contain the following visible objects: • A list of customers from which the user can select, implemented by using the DataList control. • A Text Box for entry of the customer’s Purchase Order number. • A Text Box where the date is automatically entered by code. • A Text Box where the selected customer’s identification (the value of the CustID field in the Customers table) is entered. You find out soon how to do this automatically by using the DataList control. • A list of the wines ordered, implemented as a DataGrid control. • Three command buttons. Some hidden controls are also required: • Two ADO Data controls—One each for the Customers and Items tables. You access the Invoices table without an ADO Data control. • Several Text Box controls—These serve for data transfer and temporary storage. Before you start, take a look at how the DataList control works—you’ll be using two of them in this part of the project. The DataList Control The DataList control is similar to a regular List Box control in that it displays a list of items from which the user can select. However, the DataList control can be bound to an ADO Data control so that it automatically displays the contents of a specified field in the Recordset associated with the bound ADO Data control. Two control properties determine what the DataList control displays: • RowSource—The name of the ADO Data control. • ListField—The name of the field to display in the list. Must be a valid field in the Recordset of the ADO Data control specified by the RowSource property. So far, so good. But wait, there’s more. The DataList control has BoundColumn and BoundText properties that really make it useful. The BoundColumn property specifies a field in the bound Recordset—a different field than is specified by the ListField property. When the users select an item in the DataList control, they are effectively selecting a record in the associated Recordset. The BoundText property then makes available the value of the corresponding field—the field specified by the BoundColumn property—in the selected record. This is somewhat confusing, so take a look at a specific example. When a user of your program creates an invoice, the user needs to be able to select from a list of customers. To fulfill this need, you’ll add an ADO Data control linked to the Customers table, and then bind a DataList control to that ADO Data control. You will set the ListField property to Company and the BoundColumn property to CustID. The DataList control will display a list of names of all companies in the Customers table. When the user selects a name by clicking on it, the selected customer’s CustID becomes available in the DataList control’s BoundText property. Starting The Form With the database project loaded, use the Insert Form command to add a new form to the project. Change its BorderStyle property to Fixed Single and its Caption property to New Order. Add a control array of three Command Buttons and set their Caption properties as follows: | Index 0: | &Save | Index 1: | &Add Wine
| Index 2: | &Cancel
Next, add an ADO Data control and set its properties as follows: | Name: | AdodcCustomers | Caption: | Customers
| Visible: | False
| RecordSource: | Select * from Customers order by Company
A slightly more complex SQL statement is used for the RecordSource property, to select all records from the Customers table and sort them by the Company field. Use the procedures that you learned in the previous chapter to set the control’s ConnectionString property to point to the GRAPEVINE database. Note that the Caption property is a convenience that enables you to distinguish this ADO Data control from the other controls that you will be adding. (At design time only, of course—the control isn’t visible while the program is running.) Next, add a DataList control. Remember, you may need to use the Project, Components command to add this custom control to your Toolbox. Set its properties as follows:
| Name: | DataListCustomers
| RowSource: | AdodcCustomers
| ListField: | Company
| BoundColumn: | CustID
To see how the DataList control works, you are going to print the value of its BoundText property whenever the user selects an item from the list. The place for this is in the DataListCustomers control’s Click event procedure. Add the code as follows:
    Private Sub DataListCustomers_Click()

    Debug.Print DataListCustomers.BoundText

    End Sub
The Invoices form also needs two Text Box controls, for the customer’s PO number and for the date: For the PO number Text Box, set its properties as follows: | Name: | txtCustPO | Caption: | CustPO
For the date Text Box, set its properties as follows: | Name: | txtDate | Caption: | Date
Finally, you need to add a button to the main form’s Toolbar to display the Invoices form. Add a button to the Toolbar with the caption “Orders” and then add code to the Toolbar’s ButtonClick event procedure, as shown in Listing 23.4. The new code is the Case “Orders” statement and the lines following it.
Previous | Table of Contents | Next

| Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.